package com.itheima.controller;

import com.itheima.domain.PmsBrand;
import com.itheima.manager.PmsBrandManager;
import com.itheima.manager.SmsHomeManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class PmsBrandController {
    @Autowired
    PmsBrandManager pmsBrandManager;

    /**
     * 根据品牌名称分页获取品牌列表
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/brand/list")
    public R findByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestParam(required = false) String keyword){
        return pmsBrandManager.findByPage(pageNum,pageSize,keyword);
    }

    /**
     * 添加品牌
     * @param pmsBrand
     * @return
     */
    @PostMapping("/brand/create")
    public R addBrand(@RequestBody PmsBrand pmsBrand){
        return pmsBrandManager.addBrand(pmsBrand);
    }


    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @PostMapping("/brand/delete/batch")
    public R deleteBrands(@RequestParam List<Long> ids){
        return pmsBrandManager.deleteBrands(ids);
    }

    /**
     * 根据id删除单个品牌
     * @param id
     * @return
     */
    @GetMapping("/brand/delete/{id}")
    public R deleteBrandById(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return pmsBrandManager.deleteBrands(ids);
    }

    /**
     * 获取全部品牌列表
     * @return
     */
    @GetMapping("/brand/listAll")
    public R findAllBrand(){
        return pmsBrandManager.findAllBrand();
    }


    /**
     * 批量更新厂家制造商状态
     * @param factoryStatus
     * @param ids
     * @return
     */
    @PostMapping("/brand/update/factoryStatus")
    public R updateFactoryStatus(@RequestParam Integer factoryStatus,@RequestParam List<Long> ids){
        return pmsBrandManager.updateFactoryStatus(factoryStatus,ids);
    }


    /**
     * 批量更新显示状态
     * @param showStatus
     * @param ids
     * @return
     */
    @PostMapping("/brand/update/showStatus")
    public R updateShowStatus(@RequestParam Integer showStatus,@RequestParam List<Long> ids){
        return pmsBrandManager.updateShowStatus(showStatus,ids);
    }

    /**
     * 更新品牌
     * @param id
     * @param pmsBrandParam
     * @return
     */
    @PostMapping("/brand/update/{id}")
    public R updateBrandById(@PathVariable Long id,@RequestBody PmsBrand pmsBrandParam){
        pmsBrandParam.setId(id);
        return pmsBrandManager.updateBrandById(pmsBrandParam);
    }

    /**
     * 根据编号查询品牌信息
     * @param id
     * @return
     */
    @GetMapping("/brand/{id}")
    public R findBrandById(@PathVariable Long id){
        return pmsBrandManager.findBrandById(id);
    }

}
